package com.qidian.mes.pro.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidian.mes.pojo.pro.ProProcess;
import com.qidian.mes.pojo.pro.ProRoute;
import com.qidian.mes.pojo.pro.ProRouteProcess;
import com.qidian.mes.pojo.pro.ProRouteProduct;
import com.qidian.mes.pro.mapper.ProRouteMapper;
import com.qidian.mes.pro.mapper.ProRouteProductMapper;
import com.qidian.mes.pro.service.ProRouteProductService;
import com.qidian.mes.util.pojo.MESResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 郭靖旖
 * @Company
 * @Time 2023/11/5 14:08
 * @Description
 **/
@Service
public class ProRouteProductServiceImpl implements ProRouteProductService {
    @Autowired
    ProRouteProductMapper proRouteProductMapper;
    @Override
    public MESResult selectByrouteId(int page, int limit, Long routeId) {
        PageHelper.startPage(page,limit);
        List<ProRouteProduct> list=proRouteProductMapper.selectByrouteId(routeId);
        PageInfo<ProRouteProduct> pageInfo=new PageInfo<>(list);
        return MESResult.ok(pageInfo);
    }

    @Override
    public MESResult deleteRouteProduct(Long recordId) {
        if (proRouteProductMapper.deleteRouteProduct(recordId)==1){
            return MESResult.ok();
        }
        else{
            return MESResult.fail();
        }
    }

    @Override
    public MESResult save(ProRouteProduct proRouteProduct) {
        if (proRouteProductMapper.insert(proRouteProduct)==1)
        {
            return MESResult.ok();
        }
        else
        {
            return MESResult.fail();
        }

    }

    @Override
    public MESResult update(ProRouteProduct proRouteProduct) {
        if (proRouteProductMapper.update(proRouteProduct)==1){
            return MESResult.ok();
        }
        else{
            return MESResult.fail();
        }
    }

    @Override
    public MESResult selectByPage(int page, int limit, ProRouteProduct proRouteProduct) {
        PageHelper.startPage(page,limit);
        List<ProRouteProduct> list=proRouteProductMapper.selectByPage(proRouteProduct);
        PageInfo<ProRouteProduct> pageInfo=new PageInfo<>(list);
        return MESResult.ok(pageInfo);
    }
}
